package cn.cc.goods.controller.controller;

import cn.cc.common.beanCopy.utils.BeanCopierUtil;
import cn.cc.common.result.utils.RestResult;
import cn.cc.common.result.utils.RestResultEmum;
import cn.cc.goods.controller.dto.AddGoodsTypeDTO;
import cn.cc.goods.service.GoodsTypeService;
import cn.cc.goods.service.bo.AddGoodsTypeBO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @program: smail-mi-cloud
 * @description:
 * @author: Mr.WuChao
 * @create: 2021-07-16 15:31
 **/
@RestController
@RequestMapping("/goodType")
public class GoodsTypeController {
    @Autowired
    private GoodsTypeService typeService;

    @PostMapping("/add")
    RestResult<Void> addGoodType(AddGoodsTypeDTO typeDTO) {
        AddGoodsTypeBO goodsTypeBO = BeanCopierUtil.copyObj(typeDTO, AddGoodsTypeBO.class);
        RestResult<Void> restResult = typeService.addGoodsType(goodsTypeBO);
        if (restResult.getCode().equals(RestResultEmum.SUCCESS.code)) {
            return new RestResult<>(RestResultEmum.SUCCESS.code, RestResultEmum.SUCCESS.msg);
        }
        return new RestResult<>(RestResultEmum.SAVE_ERROR.code, RestResultEmum.SAVE_ERROR.msg);
    }
}
